import { BaseWindow } from "../../../../component/window/BaseWindow";
import { IStallSellWindow } from "../interfaces/IStallSellWindow";
import { ObjCreate } from "../../common/ObjCreate";
import { Language } from "../../../../../extend/language/Language";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { SellItemData } from "../defin/SellItemData";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { ItemData } from "../../../resource/info/ItemData";
import { ColorConfig } from "../../../resource/ColorConfig";
import { ColorInfo } from "../../../resource/info/ColorInfo";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { GTextInput } from "../../../../../com/mui/controls/GTextInput";
import { GRadioButton } from "../../../../../com/mui/controls/GRadioButton";
import { GButton } from "../../../../../com/mui/controls/GButton";
type int = number;
//class SellWindow
    
    export  class SellWindow extends BaseWindow implements IStallSellWindow
    {
        constructor()
        {
            super();
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            this.initView();
            this.addListeners();
            return;
        }

        /* internal  */initView(): void
        {
            this.setSize(288, 140);
            this.titleHeight = 25;
            var loc1=ObjCreate.createBg(17, 36, 254, 65, this);
            var loc2=ObjCreate.createTextField(Language.getString(40830), 25, 55, 70, 20, this, GlobalStyle.textFormat2);
            this._priceInput = ObjCreate.createGTextInput(95, 54, 104, 20, this);
            this._priceInput.restrict = "0-9";
            this._priceInput.maxChars = 7;
            this._radionBtnCoin = ObjCreate.createRadioButton(Language.getString(40831), 210, 70, 50, 28, this);
            this._radionBtnGold = ObjCreate.createRadioButton(Language.getString(40832), 210, 47, 50, 28, this);
            this._radionBtnCoin.groupName = "StallSellType";
            this._radionBtnGold.groupName = "StallSellType";
            this._radionBtnGold.selected = true;
            this._btnOK = ObjCreate.createGButton(Language.getString(40833), 85, 106, 46, 22, this);
            this._btnCancel = ObjCreate.createGButton(Language.getString(40834), 158, 106, 46, 22, this);
            return;
        }

        /* internal  */addListeners(): void
        {
            this._btnOK.addEventListener(flash.events.MouseEvent.CLICK, this.okHandler);
            this._btnCancel.addEventListener(flash.events.MouseEvent.CLICK, this.cancelHandler);
            return;
        }

        /* internal  */okHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=0;
            var loc4=0;
            loc1 = this._itemData.uid;
            loc2 = this._itemData.itemAmount;
            if (this._radionBtnCoin.selected) 
            {
                loc4 = int(this._priceInput.text);
            }
            else 
            {
                loc3 = int(this._priceInput.text);
            }
            var loc5=new SellItemData(loc1, loc4, loc3, loc2);
            Dispatcher.dispatchEvent(new DataEvent(EventName.StallAddItem, loc5));
            this.hide();
            return;
        }

        /* internal  */cancelHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.hide();
            return;
        }

        public set data(arg1: Object)
        {
            var loc1=null;
            this._itemData = null;
            if (typeof arg1 === "itemdata") 
            {
                this._itemData = arg1 as ItemData;
                loc1 = this._itemData.itemInfo.item.name + (this._itemData.itemAmount > 1 ? "X" + this._itemData.itemAmount.toString() : "");
                this.changeTitle(loc1, ColorConfig.instance.getItemColor(this._itemData.itemInfo.item.color));
                this._priceInput.text = "1";
            }
            return;
        }

        /* internal  */changeTitle(arg1: string, arg2: ColorInfo): void
        {
            if (!this._titleSp) 
            {
                this._titleSp = new Object /* flash.display.Sprite */();
            }
            if (!this._titleLable) 
            {
                this._titleLable = ObjCreate.createTextField("");
            }
            this._titleLable.y = 4;
            this._titleSp.addChild(this._titleLable);
            this._titleLable.mouseEnabled = false;
            this._titleLable.selectable = false;
            this._titleLable.filters = [FilterConst.glowFilter];
            this._titleLable.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._titleLable.htmlText = HTMLUtil.addColor(arg1, arg2.color);
            title = this._titleSp;
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            this._priceInput.setFocus();
            return;
        }

        /* internal */ /* var */_itemData: ItemData;

        /* internal */ /* var */_priceInput: GTextInput;

        /* internal */ /* var */_radionBtnCoin: GRadioButton;

        /* internal */ /* var */_radionBtnGold: GRadioButton;

        /* internal */ /* var */_btnOK: GButton;

        /* internal */ /* var */_btnCancel: GButton;

        /* internal */ /* var */_titleLable: Object /* flash.text.TextField */;

        /* internal */ /* var */_titleSp: Object /* flash.display.Sprite */;
    }
